import multiprocessing

from loguru import logger

# 定义全局变量
my_list = []


def write_data():
    """写入数据"""
    for i in range(3):
        my_list.append(i)
    logger.debug(my_list)


def read_data():
    """读取数据"""
    logger.debug(my_list)


if __name__ == '__main__':
    # 创建写入数据进程
    write_process = multiprocessing.Process(target=write_data)
    # 创建读取数据进程
    read_process = multiprocessing.Process(target=read_data)

    # 启动进程执行写入数据
    write_process.start()
    # 启动进程执行读取数据
    read_process.start()

    # 主进程等待子进程执行结束后再继续往下执行
    write_process.join()
    logger.debug(my_list)
